/**
 * Title：Utility.java
 * Description: 工具类
 * Function: 判断是否为空,等方法
 * Copyright: Copyright (c) 2011-05-30
 * Company: Camelot
 * Author : liuhao
 * Version 1.0
 */
package com.camelot.ccr.global.util;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.multipart.MultipartFile;


/**
 * <pre>
 * 輔助工具類
 * </pre>
 * @author Liu Jun
 * @version V0.1, 2013-12-27 上午11:02:24
 */
public class Utility {

	public static final String TIME_STAMP_DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss";// 固定时间格式
	/**
	 * 默认yy-MM-dd时间格式
	 */
	public static final String DATE_DEFAULT_PATTERN = "yyyy-MM-dd";// 时间格式
	
	/**
	 *  时间格式 
	 */
	public static final String DATE_DEFAULT_PATTERN_YM = "yyyy-MM";
	
	/**
	 *  时间格式 
	 */
	public static final String DATE_DEFAULT_PATTERN_Y = "yyyy";
	
	public static final String ORACLE_DETATIME_PATTERN = "yyyy-MM-dd HH24:mi:ss";//oracle的时间格式
	
	public static final String DATE_PATTERN = "yyyyMMdd";// 时间格式
	
	public static final String DATE_MD_PATTERN = "yyMMdd";

	public static final String NUMBER_DEFAULT_PATTERN_STR = "#,##0.00";// 数值格式

	public static final String NUMBER_DEFAULT_PATTERN = "###0.00";// 默认格式化数字格式
	
	public static final String NUMBER_THREE_PATTERN = "###0.000";//三位小数
	
	public static final String NUMBER_DIGIT = "###0";//整数

	public static final String TOP_TIME = "00:00:00";//

	public static final String BOTTOM_TIME = "23:59:59";//

	public static final String SPLIT_FLAG = ",";

	public static final String SPLIT_DOUBLE_LINE_FLAG = "||";
	


	/**
	 * <pre>
	 * 判断字符串是否为空
	 * </pre>
	 * @param str str
	 * @return 返回真假
	 * @author Liu Jun, 2013-12-27 上午11:10:50
	 */
	public static boolean isEmpty(String str) {
		return str == null || str.trim().length() == 0;
	}

	/**
	 * 判断字符串是否不为空
	 * @param str str
	 * @return 返回布尔
	 */
	public static boolean isNotEmpty(String str) {
		return str != null && str.trim().length()>0;
	}

	/**
	 * 判断数组是否不为空
	 * 
	 * @param objArray  目标数组
	 * @return 返回布尔
	 */
	public static boolean isNotEmpty(Object... objArray) {
		return objArray != null && objArray.length > 0;
	}
	/**
	 * <pre>
	 * 判断对象是否为空
	 * </pre>
	 * @param obj 对象
	 * @return 布尔
	 * @author Liu Jun, 2013-12-27 上午11:16:59
	 */
	public static boolean isNotEmpty(Object obj) {
		return obj != null;
	}

	/**
	 * <pre>
	 * 判断集合类是否不为空
	 * </pre>
	 * @param col 集合类
	 * @return boolea
	 * @author Liu Jun, 2014-1-3 下午6:37:22
	 */
	public static boolean isNotEmpty(Collection<?> col) {
		return !CollectionUtils.isEmpty(col);
	}
	/**
	 * <pre>
	 * 判断集合类是否为空
	 * </pre>
	 * @param col 集合类
	 * @return boolea
	 * @author Liu Jun, 2014-1-3 下午6:37:22
	 */
	public static boolean isEmpty(Collection<?> col) {
		return CollectionUtils.isEmpty(col);
	}
	/**
	 * Description:判断对象是否为空 liujun Jan 16, 2012
	 * 
	 * @param o 对象
	 * @return 布尔
	 */
	public static boolean isNull(Object o) {
		if (o instanceof String) {
			return Utility.isEmpty((String) o);
		}
		return o == null ? true : false;
	}

	/**
	 * Description:判断对象是否不为空 liujun Jan 16, 2012
	 * 
	 * @param o 对象
	 * @return 布尔
	 */
	public static boolean isNotNull(Object o) {
		if (o instanceof String) {
			return Utility.isNotEmpty((String) o);
		}
		return o == null ? false : true;
	}

	/**
	 * 把一个时间格式的字符串转变为特定格式的时间
	 * 
	 * @param strDate  转换的时间
	 * @param pattern  转换的格式
	 *            
	 * @return 返回时间类型
	 */
	public static Timestamp convertStringToTimestamp(String strDate,String pattern){
		java.sql.Timestamp lStamp = null;
		if (strDate == null || strDate.length() == 0) {
			lStamp = new java.sql.Timestamp(System.currentTimeMillis());
		} else {
			if (pattern == null || pattern.length() == 0) {
				try {
					lStamp = java.sql.Timestamp.valueOf(strDate);
				} catch (Exception e) {
					lStamp = new java.sql.Timestamp(System.currentTimeMillis());
				}
			} else {
				try {
					SimpleDateFormat lFormat = new SimpleDateFormat(pattern);
					lStamp = new java.sql.Timestamp(lFormat.parse(strDate).getTime());
				} catch (Exception e) {
					lStamp = new java.sql.Timestamp(System.currentTimeMillis());
				}
			}
		}
		return lStamp;
	}

	/**
	 * 把时间格式格式化为特定格式的时间
	 * 
	 * @param strTime 要转换的时间
	 * @param pattern 要转换的格式
	 * @return  转后的字符串
	 */
	public static String convertTimestampToString(Date strTime, String pattern){
		if (strTime == null){
			return null;
		}
		SimpleDateFormat lFormat = new SimpleDateFormat();
		if ((pattern != null) && (pattern.length() > 0)){
			lFormat.applyPattern(pattern);
			
		}else{
			lFormat.applyPattern(DATE_DEFAULT_PATTERN);
		}
		return lFormat.format(strTime);
	}

	/**
	 * 格式化数字
	 * 
	 * @param db double
	 * @param pattern 格式化类型
	 * @return 字符串
	 */
	public static String convertDoubleToString(Double db, String pattern) {
		if (db == null) {
			return null;
		}
		DecimalFormat decimalFormat = new DecimalFormat(pattern);
		return decimalFormat.format(db.doubleValue());
	}
	
	/**
	 * 格式化数字
	 * 
	 * @param db 要格式化的数字
	 * @param pattern 数字个格式
	 * @param isConverZero 当数字为空是返回0      
	 * @return 转后的字符串
	 */
	public static String convertDoubleToString(Double db, String pattern,boolean isConverZero) {
		if (db == null) {
			if(isConverZero){
				return "0";
			}else{
				return null;
			}
		}
		DecimalFormat decimalFormat = new DecimalFormat(pattern);
		return decimalFormat.format(db.doubleValue());
	}

	/**
	 * 把数字格式的字符串转变为特定格式的数字
	 * @param dbStr 要转换的字符串
	 * @param pattern 格式
	 * @return 转后后的数字
	 */
	public static Double convertStringToDouble(String dbStr, String pattern) {
		if (dbStr == null || dbStr.length() == 0) {
			return null;
		}
		Double dbTemp = null;
		try {
			dbTemp = Double.valueOf(dbStr);
		} catch (Exception e) {
			dbTemp = null;
			return null;
		}
		Double dbReturn = null;
		if (pattern != null && pattern.length() > 0) {
			DecimalFormat decimalFormat = new DecimalFormat(pattern);
			dbReturn = Double.parseDouble(decimalFormat.format(dbTemp));
		} else {
			dbReturn = dbTemp;
		}
		return dbReturn;
	}

	/**
	 * <pre>
	 * 获取特定格式化后的数字
	 * </pre>
	 * @param dbVal 指定Double类型值
	 * @param pattern 格式化的格式
	 * @return  Double
	 * @author Liu Jun, 2013-12-27 下午3:25:03
	 */
	public static Double getFormatedDouble(Double dbVal, String pattern) {
		if (dbVal == null) {
			return null;
		}
		Double dbReturn = null;
		if (pattern != null && pattern.length() > 0) {
			DecimalFormat decimalFormat = new DecimalFormat(pattern);
			dbReturn = Double.parseDouble(decimalFormat.format(dbVal));
		} else {
			dbReturn = dbVal;
		}
		return dbReturn;
	}

	/**
	 * 获取当前时间
	 * 
	 * @return Timestamp
	 */
	public static Timestamp getNowTimestamp() {
		return new Timestamp(System.currentTimeMillis());
	}
	
	/**
	 * 获取当前时间的字符串 格式化为 年-月-日 时-分-秒
	 * @return String
	 */
	public static String getNowTimestampString() {
		Timestamp nowTime = getNowTimestamp();
		String formatTime = convertTimestampToString(nowTime,TIME_STAMP_DEFAULT_PATTERN);
		return formatTime;
	}
	/**
	 * <pre>
	 * 获取当前年
	 * </pre>
	 * @return String
	 * @author Liu Jun, 2013-12-27 下午3:26:32
	 */
	public static String getNowYear(){
		Timestamp nowTime = getNowTimestamp();
		String year = convertTimestampToString(nowTime,DATE_DEFAULT_PATTERN_Y);
		return year;
	}
	/**
	 * 字符串转变为整数
	 * 
	 * @param val 数值型字符串
	 * @return Integer
	 */
	public static Integer convertStringToInteger(String val) {
		if (null == val || val.length() == 0){
			return null;
		}
		Integer intVal = 0;
		try {
			intVal = Integer.parseInt(val);
		} catch (Exception e) {
			intVal = 0;
		}
		return intVal;
	}

	/**
	 * 字符串转变为整数
	 * 
	 * @param val 数字型字符串
	 * @return int
	 */
	public static int convertStringToInt(String val) {
		if (null == val || val.length() == 0){
			return 0;
		}
		int intVal = 0;
		try {
			intVal = Integer.parseInt(val);
		} catch (Exception e) {
			intVal = 0;
		}
		return intVal;
	}

	/**
	 * 字符串拼接
	 * @param a a
	 * @param b b
	 * @return String
	 */
	public static String stringAppendString(String a, String b) {
		if (Utility.isEmpty(a) && Utility.isEmpty(b)){
			return "";
		}
		else if (Utility.isNotEmpty(a) && Utility.isEmpty(b)){
			return a;
		}
		else if (Utility.isEmpty(a) && Utility.isNotEmpty(b)){
			return b;
		}
		else if (Utility.isNotEmpty(a) && Utility.isNotEmpty(b)){
			return a + "," + b;
		}
		return "";
	}

	/**
	 * 从数组中返回指定下标的值
	 * 
	 * @param <T> 泛型实体
	 * @param objArray 目标数组
	 * @param index 下标值
	 * @return Object
	 */
	public static <T> Object getObjectValueFormObjectArray(Object[] objArray, int index) {
		if (null == objArray){
			return null;
		}
		Object returnValue = null;
		if (index < objArray.length) {
			returnValue = objArray[index];
		}
		return returnValue;
	}

	/**
	 * 从数组中返回指定下标的字符串值
	 * 
	 * @param objArray 目标数组
	 * @param index 下标值
	 * @return String
	 */
	public static String getStringValueFormObjectArray(Object[] objArray, int index) {
		if (null == objArray){
			return "";
		}
		String returnValue = null;
		if (index < objArray.length) {
			returnValue = null != objArray[index] ? String.valueOf(objArray[index]) : "";
		}
		return returnValue;
	}

	/**
	 * 从数组中返回指定下标的整型值
	 * 
	 * @param objArray 目标数组
	 * @param index 下标值
	 * @return Integer
	 */
	public static Integer getIntegerValueFormObjectArray(Object[] objArray, int index) {
		if (null == objArray){
			return null;
		}
		Integer returnValue = null;
		if (index < objArray.length) {
			returnValue = null != objArray[index] ? Integer.valueOf(String.valueOf(objArray[index])) : null;
		}
		return returnValue;
	}

	/**
	 * 从数组中返回指定下标的长整形
	 * 
	 * @param objArray 目标数组
	 * @param index 下标值
	 * @return Integer
	 */
	public static Long getLongValueFormObjectArray(Object[] objArray, int index) {
		if (null == objArray){
			return null;
		}
		Long returnValue = null;
		if (index < objArray.length) {
			returnValue = null != objArray[index] ? Long.valueOf(String.valueOf(objArray[index])) : null;
		}
		return returnValue;
	}
	
	/**
	 * 从数组中返回指定下标的BigDecimal值
	 * 
	 * @param objArray  目标数组
	 * @param index  下标
	 * @return  BigDecimal
	 */
	public static BigDecimal getBigDecimalValueFormObjectArray(Object[] objArray, int index) {
		if (null == objArray){
			return null;
		}
		BigDecimal returnValue = null;
		if (index < objArray.length) {
			returnValue = null != objArray[index] ? new BigDecimal(String.valueOf(objArray[index])) : null;
		}
		return returnValue;
	}

	/**
	 * 从数组中返回指定下标的浮点值
	 * 
	 * @param objArray 目标数组
	 * @param index 下标
	 * @return Double
	 */
	public static Double getDoubleValueFormObjectArray(Object[] objArray, int index) {
		if (null == objArray){
			return null;
		}
		Double returnValue = null;
		if (index < objArray.length) {
			returnValue = null != objArray[index] ? Double.valueOf(String.valueOf(objArray[index])) : null;
		}
		return returnValue;
	}

	/**
	 * 从数组中返回指定下标的Timestamp值
	 * 
	 * @param objArray 目标数组
	 * @param index 下标值
	 * @param pattern 格式
	 * @return Timestamp
	 */
	public static Timestamp getTimestampValueFormObjectArray(Object[] objArray, int index, String pattern) {
		if (null == objArray){
			return null;
		}
		Timestamp returnValue = null;
		if (index < objArray.length) {
			returnValue = null != objArray[index] ? convertStringToTimestamp(String.valueOf(objArray[index]), pattern)
					: null;
		}
		return returnValue;
	}


	/**
	 * 获取特定语言对应文字
	 * 
	 * @param asKey key
	 * @param asLocale 语言环境
	 * @param arg 参数
	 * @return String
	 */
	public static String getMessage(String asKey, Locale asLocale, Object... arg) {
		String msg = getMessage(asKey, asLocale);
		return MessageFormat.format(msg, arg);
	}
	/**
	 * 判断字符串是否是Null、""和"null"
	 * @param str str
	 * @return String
	 */
	public static String convertNullString(String str){
		if(isEmpty(str)){
			return "";
		}
		if("null".equalsIgnoreCase(str)){
			return "";
		}else{
			return str;
		}
	}
	
	/**
	 * <pre>
	 * 得到今天的0点0分0秒
	 * </pre>
	 * @return Timestamp
	 * @author Liu Jun, 2013-12-27 下午3:06:02
	 */
	public static Timestamp getTodayTopTime() {
		Date date = new Date();
		String topTime = convertTimestampToString(date, DATE_DEFAULT_PATTERN) + " " + TOP_TIME;
		return convertStringToTimestamp(topTime, TIME_STAMP_DEFAULT_PATTERN);
	}
	
	/**
	 * <pre>
	 * 得到今天的23点59分59秒
	 * </pre>
	 * @return Timestamp
	 * @author Liu Jun, 2013-12-27 下午3:06:40
	 */
	public static Timestamp getTodayBottomTime() {
		Date date = new Date();
		String topTime = convertTimestampToString(date, DATE_DEFAULT_PATTERN) + " " + BOTTOM_TIME;
		return convertStringToTimestamp(topTime, TIME_STAMP_DEFAULT_PATTERN);
	}
	
	/**
	 * <pre>
	 * 得到某月第一天
	 * </pre>
	 * @param month  month
	 * @return Date
	 * @author Liu Jun, 2013-12-27 下午3:06:52
	 */
	public static Date getFirstDayOfMonth(int month){
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.MONTH, month-1);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return calendar.getTime();
	}
	
	
	/**
	 * <pre>
	 * 得到去年12月第一天
	 * </pre>
	 * @return Date
	 * @author Liu Jun, 2013-12-27 下午3:07:25
	 */
	public static Date getFirstDayOfLastDecember(){
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.YEAR, -1);
		calendar.set(Calendar.MONTH, 11);
		calendar.set(Calendar.DATE, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return calendar.getTime();
	}
	/**
	 * <pre>
	 * 得到今年的第一天
	 * </pre>
	 * @return Date
	 * @author Liu Jun, 2013-12-27 下午3:07:53
	 */
	public static Date getFirstDayOfThisYear() {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.MONTH, 0);
		calendar.set(Calendar.DATE, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0); 
		calendar.set(Calendar.SECOND, 0);
		return calendar.getTime();
	}
	
	
	
	/**
	 * 得到某月的第一天
	 * @param month 指定的月份
	 * @param strParttern 格式化格式
	 * @return String
	 */
	public static String getStringFirstDayOfMonth(int month,String strParttern){
		if (isEmpty(strParttern)){
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.MONTH, month-1);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return convertTimestampToString(calendar.getTime(), strParttern);
	}
	
	/**
	 * 得到某月的第一天
	 * @param month 指定的月份
	 * @param strParttern 格式化格式
	 * @return String
	 */
	public static String getStringFirstDayOfNextMonth(int month,String strParttern){
		if (isEmpty(strParttern)){
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return convertTimestampToString(calendar.getTime(), strParttern);
	}
	
	
	/**
	 * 得到今年的第一天
	 * @param strParttern 格式化格式
	 * @return String
	 */
	public static String getStringFirstDayOfYear(String strParttern){
		if (isEmpty(strParttern)){
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.MONTH, 0);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return convertTimestampToString(calendar.getTime(), strParttern);
	}
	
	/**
	 * 得到明年的第一天
	 * @param strParttern 格式化格式
	 * @return String
	 */
	public static String getStringFirstDayOfNextYear(String strParttern){
		if (isEmpty(strParttern)){
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.MONTH, 0);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.add(Calendar.YEAR, 1);
		return convertTimestampToString(calendar.getTime(), strParttern);
	}
	
	
	/**
	 * 获取制定时间所在月份的第一天的零点零分零秒
	 * @param strTime 指定的时间
	 * @param strParttern 格式化的样式
	 * @return String
	 */
	public static String convertFirstDayOfMonth(Date strTime,String strParttern) {
		if (isEmpty(strParttern)){
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(strTime);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return convertTimestampToString(calendar.getTime(), strParttern);
	}
	
	/**
	 * 获取下一个月的第一天的零点零分零秒
	 * @param strTime 指定的时间
	 * @param strParttern 格式化的样式
	 * @return String
	 */
	public static String convertFirstDayOfNextMonth(Date strTime,String strParttern) {
		if (isEmpty(strParttern)){
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(strTime);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.add(Calendar.MONTH, 1);
		return convertTimestampToString(calendar.getTime(), strParttern);
	}
	
	/**
	 * 获取制定日期月份的最后一天的23点59分59秒
	 * @param strTime 要格式化的日期
	 * @param strParttern 格式化的样式
	 * @return String
	 */
	public static String convertLastDayOfMonth(Date strTime,String strParttern) {
		if (isEmpty(strParttern)){
			return null;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(strTime);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 23);
		calendar.set(Calendar.MINUTE, 59);
		calendar.set(Calendar.SECOND, 59);
		calendar.add(Calendar.MONTH, 1);
		calendar.add(Calendar.DAY_OF_MONTH, -1);
		return convertTimestampToString(calendar.getTime(), strParttern);
	}
	/**
	 * 得到当前月份的int值
	 * @return 当前月
	 */
	public static int getNowMonth() {
		Calendar cal = Calendar.getInstance();
		return cal.get(Calendar.MONTH) + 1;
	}
	
	/**
	 * <pre>
	 * 一年最开始时间
	 * </pre>
	 * @param year 年
	 * @return String
	 * @author Liu Jun, 2013-12-27 下午2:58:49
	 */
	public static String getBeginTimeOfYear(int year){
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, 0);
		calendar.set(Calendar.DATE, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		return convertTimestampToString(calendar.getTime(), TIME_STAMP_DEFAULT_PATTERN);
	}
	
	/**
	 * <pre>
	 * 一年最后时间
	 * </pre>
	 * @param year year
	 * @return String
	 * @author Liu Jun, 2013-12-27 下午3:00:45
	 */
	public static String getEndTimeOfYear(int year){
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, year + 1);
		calendar.set(Calendar.MONTH, 0);
		calendar.set(Calendar.DATE, 1);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.add(Calendar.SECOND, -1);
		return convertTimestampToString(calendar.getTime(), TIME_STAMP_DEFAULT_PATTERN);
	}
	
	/**
	 * <pre>
	 * randomColor
	 * </pre>
	 * @return 顏色
	 * @author Liu Jun, 2013-12-27 下午2:49:27
	 */
	public static String randomColor(){
		char[] colorChar = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
		String color = "";
		for(int i = 0; i < 6; i++){
			int index = (int) (Math.random() * 16);
			color += colorChar[index];
		}
		return color;
	}
	
	/**
	 * 根据月份转变成数字
	 * @param monthStr 得到的字符
	 * @return 返回轉換的月份
	 * @throws Exception
	 */
	public static int convertStrMonth(String monthStr){
		int month = Utility.getNowMonth();
		try {
			if (Utility.isNotEmpty(monthStr)){
				month = Integer.parseInt(monthStr);
			}
		}catch (Exception e) {
			month = Utility.getNowMonth();
		}
		return month;
	}
	/**
	 * <pre>
	 * 截取字符串方法支持,和'
	 * </pre>
	 * @param <T> 泛型實體
	 * @param args args
	 * @return String
	 * @author Liu Jun, 2013-12-27 下午2:50:59
	 */
	public static <T> String toTokenString(T ...args){
	    return toTokenString(", ", "'", args);
	}
	/**
	 * <pre>
	 * 截取字符串方法支持
	 * </pre>
	 * @param <T> 泛型实体
	 * @param separator 分隔符
	 * @param qoute qoute
	 * @param args args
	 * @return String
	 * @author Liu Jun, 2013-12-27 下午2:53:38
	 */
	public static <T> String toTokenString(String separator, String qoute, T ...args){
	    return toTokenString(separator, qoute, qoute, args);
	}
	/**
	 * <pre>
	 * 截取字符串方法支持
	 * </pre>
	 * @param <T> 泛型实体
	 * @param separator 分隔符
	 * @param lqoute lqoute
	 * @param rqoute rqoute
	 * @param args  args
	 * @return String
	 * @author Liu Jun, 2013-12-27 下午2:54:14
	 */
	public static <T> String toTokenString(String separator, String lqoute, String rqoute, T ...args){
	    if(args.length == 0){
	    	return null;
	    }
	    StringBuilder buf = new StringBuilder();
	    for(int i=0; i<args.length; i++){
	        if(i != 0){
	            buf.append(separator);
	        }
	        if(args[i] != null){
	            buf.append(lqoute).append(String.valueOf(args[i])).append(rqoute);
	        }
	    }
	    return buf.toString();
	}
	/**
	 * <pre>
	 * <请输入描述信息>
	 * </pre>
	 * @param <E> 枚举泛型
	 * @param anEnum 枚举
	 * @return E
	 * @author Liu Jun, 2013-12-27 下午2:56:26
	 */
	public static <E extends Enum<E>> E[] allLessThan(Enum<E> anEnum){
	    Method valuesMethod = ReflectionUtils.findMethod(anEnum.getClass(), "values");
	    E[] values = (E[])ReflectionUtils.invokeMethod(valuesMethod, null);
	    List<E> result = new ArrayList<E>();
	    for(E e : values){
	        if(e.ordinal() < anEnum.ordinal()){
	        	result.add(e);
	        }
	    }
	    E[]  target = (E[])Array.newInstance(anEnum.getClass(), 0);
	    
	    return result.toArray(target);
	}
	
	/**
	 * 
	 * <pre>
	 * 将yyyy-mm-dd hh:MM:ss格式的数据格式化为yyyy-mm-dd格式
	 * </pre>
	 * @param date 数据源
	 * @return yyyy-mm-dd格式的数据
	 * @author Niu Lina, 2014-2-21 下午4:51:56
	 */
	public static Date formatTimeToDate(Date date)
	{
		String dateDource = String.valueOf(date);
		dateDource = dateDource.substring(0, 11);
		SimpleDateFormat sdf = new SimpleDateFormat(DATE_DEFAULT_PATTERN);
		try {
	        return sdf.parse(dateDource);
        } catch (ParseException e) {
	        e.printStackTrace();
	        throw new RuntimeException(e);
        }
	}
	
	/**
	 * <pre>
	 * <文件上传辅助类>
	 * </pre>
	 * @param file
	 * @param logoRealPathDir
	 * @return
	 * @throws IOException
	 * @author Liu Jun, 2014-5-24 上午10:35:17
	 */
	public static String uploadFile(MultipartFile file, String logoRealPathDir,String modulePath) throws IOException {
		String uuid = UUID.randomUUID().toString();
		File f = new File(logoRealPathDir);
		if(!f.exists()){
			f.mkdirs();
		}
		/**获取文件的后缀**/    
        String suffix = file.getOriginalFilename().substring  
                        (file.getOriginalFilename().lastIndexOf("."));
        String photoRealPath = logoRealPathDir+File.separator + uuid+ suffix; 
        String photoAbousationPath = modulePath+File.separator + uuid+ suffix; 
		file.transferTo(new File(photoRealPath));
		return photoAbousationPath;
	}
}
